package com.tencent.wework.demo

import android.graphics.Color
import android.view.ViewGroup
import com.tencent.wework.list.BaseRecyclerCell
import com.tencent.wework.list.BaseViewHolder
import com.tencent.wework.list.R
import kotlinx.android.synthetic.main.demo_item_layout.view.*

/**
 * Created by huangwei on 2019/5/27.
 */
open class DemoItemCell(data: ItemData,val pagerMode:Boolean=false):BaseRecyclerCell<ItemData>(data) {

    private var isSelect = false
    override fun createViewHolder(parent: ViewGroup): BaseViewHolder {
        return inflateLayout(R.layout.demo_item_layout,parent)
    }

    override fun onBindViewHolder(viewHolder: BaseViewHolder) {
        val itemView = viewHolder.itemView
        if(pagerMode){
            val params = itemView.layoutParams
            params.height = ViewGroup.LayoutParams.MATCH_PARENT
            itemView.layoutParams = params
        }
        itemView.nameTxt.text = data.name
        itemView.contentTxt.text = data.content
        itemView.setBackgroundColor(if(isSelect) Color.RED else 0)
        itemView.setOnClickListener {
            isSelect = !isSelect
            itemView.setBackgroundColor(if(isSelect) Color.RED else 0)
        }
    }
}

data class ItemData(val name:String,val content:String)